/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.study.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.sql.Date;

/**
 *
 * @author Truong Anh Tuan
 */
public class DateUtil {

    public DateUtil() {
    }
    

    public static Date convert2Date(String value, String pattern) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            java.util.Date d = format.parse(value);
            Calendar ca = Calendar.getInstance();
            ca.setTime(d);
            return new Date(ca.getTimeInMillis());
        } catch (ParseException ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public static String convert2String(Date d, String pattern) {
        return new SimpleDateFormat(pattern).format(d);
    }
}
